package com.qf.controller;

import com.qf.dto.RepairDto;
import com.qf.entity.Repair;
import com.qf.result.ResponseResult;
import com.qf.service.RepairService;
import com.qf.utils.BeanCopyUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/repair")
@Api(tags = "维修模块", description = "维修相关接口")
public class RepairController {

    @Autowired
    private RepairService repairService;

    @GetMapping("/getRepairList")
    @ApiOperation(value = "维修列表", notes = "获取所有维修列表")
    public ResponseResult getRepairList(){
        return repairService.getRepairList();
    }

    @DeleteMapping("/deleteRepair/{id}")
    @ApiOperation(value = "删除维修记录", notes = "删除一条维修记录")
    public ResponseResult deleteRepair(@PathVariable Integer id){
        return repairService.deleteRepair(id);
    }

    @PutMapping("/updateRepair")
    @ApiOperation(value = "更新维修记录", notes = "修改一条维修记录")
    public ResponseResult updateRepair(@RequestBody @Valid RepairDto repair){
        return repairService.updateRepair(BeanCopyUtils.copyBean(repair,Repair.class));
    }

    @PostMapping("/saveRepair")
    @ApiOperation(value = "添加维修记录", notes = "添加一条维修记录")
    public ResponseResult saveRepair(@RequestBody @Valid RepairDto repair){
        return repairService.saveRepair(BeanCopyUtils.copyBean(repair,Repair.class));
    }

    @GetMapping("/likeRepairMsg")
    @ApiOperation(value = "模糊查询维修记录", notes = "查询多条维修记录,根据维修信息")
    public ResponseResult likeRepairMsg(String repairMsg){
        return repairService.likeRepairMsg(repairMsg);
    }

}
